﻿using MesErreurs;
using Metier;
using Persistance;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Utilitaires;

namespace Gestion_commerciale
{
    public partial class FInser_Cde : Form
    {
        public FInser_Cde()
        {
            InitializeComponent();
            List<String> mesNumeros;
            try
            {
                // Lecture classique
                Clientel unClient = new Clientel();          
                mesNumeros = unClient.LectureNoClient();
                foreach (String item in mesNumeros)
                {
                    CClient.Items.Add(item);
                }
            }
            catch (MonException exception)
            {
                MessageBox.Show(exception.MessageApplication(), exception.Message);
            }

            try
            {
                // Lecture classique
                Vendeur unVendeur = new Vendeur();
                mesNumeros = unVendeur.LectureNoVendeur();
                foreach (String item in mesNumeros)
                {
                    CVendeur.Items.Add(item);
                }
            }
            catch (MonException exception)
            {
                MessageBox.Show(exception.MessageApplication(), exception.Message);
            }
        }

        private void bInserer_Click(object sender, EventArgs e)
        {
            Commande commande = new Commande();
            try
            {
                commande.insererCommande(CNumCommande.Text, CVendeur.Text, CClient.Text, Fonctions.DateToString(CDate.Value));
            }
            catch (MonException exception)
            {
                MessageBox.Show(exception.MessageApplication(), exception.Message);
            }
            Close();
        }

        private void CNumCommande_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }
    }
}
